package com.halachawiki.client;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.halachawiki.client.login.ChangePasswordControl;
import com.halachawiki.client.login.LoginControl;
import com.halachawiki.shared.PublicUserInfo;


public class UserMenu extends VerticalPanel {
	public UserMenu(PublicUserInfo userInfo, final LoginControl loginControl) {
		MenuBar menuBar = new MenuBar();
		add(menuBar);
		final VerticalPanel changePasswordControlContainer = new VerticalPanel();
		add(changePasswordControlContainer);
		MenuBar subMenu = new MenuBar(true);
		menuBar.addItem(userInfo.displayName, subMenu);
		subMenu.addItem("Change password", new Command() {
			@Override
			public void execute() {
				changePasswordControlContainer.clear();
				ChangePasswordControl changePasswordControl = new ChangePasswordControl();
				changePasswordControlContainer.add(changePasswordControl.getRoot());
				changePasswordControl.draw();
			} 
		});
		subMenu.addItem("Logout", new Command() {
			@Override
			public void execute() {
				changePasswordControlContainer.clear();
				loginControl.logout(new Command() {
					@Override
					public void execute() {
						Window.Location.reload();
					} 
				});
			}
		});
	}
}
